<!-- 投标文件审核 -->
<template>
	<view class="page">
		<u--form
			labelPosition="top"
			:model="model"
			ref="ErpOmcProjectApplyForm"
			:rules="rules"
			labelWidth="auto"
			:labelStyle="{
				fontSize: '14px',
				color: '#B2B2B2',
				lineHight: '20px'
			}"
		>
			<view class="basic-style">
				<u-form-item
					label="单据编号"
					prop="bidNo"
					:borderBottom="false"
					required
				>
					<u--input
						disabled
						placeholder="请输入单据编号"
						v-model="model.bidNo"
					></u--input>
				</u-form-item>
				<u-form-item
					label="日期"
					prop="createTime"
					:borderBottom="false"
					required
				>
					<u--input
						v-model="model.createTime"
						disabled
						placeholder="请选择日期"
						border="surround"
						suffixIcon="calendar-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="申请人"
					prop="proposer"
					:borderBottom="false"
					required
				>
					<h-select-person-input
						style="width: 100%"
						disabled
						v-model="model.proposer"
						placeholder="请选择申请人"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
						objectField="model.proposer"
					></h-select-person-input>
				</u-form-item>
				<u-form-item
					label="申请部门"
					prop="proposerDeptId"
					:borderBottom="false"
					required
				>
					<h-select-depart-input
						disabled
					  v-model="model.proposerDeptId"
					  :departName="model.proposerDeptText"
					  placeholder="请选择部门"
					  border="surround"
					  style="width: 100%"
					  suffixIcon="arrow-down-fill"
					  :suffixIconStyle="{ color: '#B2B2B2' }"
					  :title.sync="model.proposerDeptText"
					  @detail="ontenderDeptDetail"
					></h-select-depart-input>
				</u-form-item>
				<view class="basic-title-center">
					<u-line :length="120"></u-line>
					<view class="">基本信息</view>
					<u-line :length="120"></u-line>
				</view>
				<u-form-item
					label="关联投标档案"
					prop="tenderId"
					:borderBottom="false"
					required
				>
					<h-select-omc-project-tender-input
						v-model="model.tenderId"
						style="width: 100%"
						placeholder="请选择关联投标档案"
						objectField="model.tenderId"
						:dataType="'emp'"
						:dataIsolation="'tender_person'"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"
						@input="tenderFinalChange"
					></h-select-omc-project-tender-input>
				</u-form-item>
				<u-form-item
					label="项目名称"
					prop="projectName"
					:borderBottom="false"
					required
				>
					<u--input
						placeholder="请输入项目名称"
						v-model="model.projectName"
					></u--input>
				</u-form-item>
				<u-form-item
					label="项目承接人"
					prop="undertaker"
					:borderBottom="false"
					required
				>
					<h-select-person-input
						style="width: 100%"
						v-model="model.undertaker"
						placeholder="请选择项目承接人"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
						objectField="model.undertaker"
					></h-select-person-input>
				</u-form-item>
				<u-form-item
					label="业绩归属年度"
					prop="year"
					:borderBottom="false"
					required
				>
					<h-dict-select
						style="width: 100%" 
						v-model="model.year" 
						placeholder="请选择业绩归属年度" 
						dictName="yjgsnd" 
						suffixIcon="arrow-down-fill" 
						:suffixIconStyle="{color: '#B2B2B2'}"
					></h-dict-select>
				</u-form-item>
				<u-form-item
					label="项目地址"
					prop="projectAddress"
					:borderBottom="false"
					required
				>
					<h-select-address-input
						style="width: 100%"
						v-model="model.projectAddress"
						placeholder="请选择项目地址"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></h-select-address-input>
				</u-form-item>
				<u-form-item
					label="项目详细地址"
					prop="detailedAddress"
					:borderBottom="false"
					required
				>
					<u--input
						placeholder="请输入项目详细地址"
						v-model="model.detailedAddress"
					></u--input>
				</u-form-item>
				<u-form-item
					label="经营团队"
					prop="businessTeam"
					:borderBottom="false"
					required
				>
					<h-select-team-input
					@input="changeBusinessCompany"
						style="width: 100%;"
						v-model="model.businessTeam"
						objectField="model.businessTeam"
						placeholder="请选择经营团队"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
						:tdlx="1"
					></h-select-team-input>
				</u-form-item>
				<!-- <u-form-item
				label="经营公司"
				prop="businessCompanyId"
				:borderBottom="false"
				required>
				<h-select-company-input
					disabled
					style="width: 100%"
					v-model="model.businessCompanyId"
					border="surround"
					placeholder="请选择经营公司"
					suffixIcon="arrow-down-fill"
					:suffixIconStyle="{color: '#B2B2B2'}"
					objectField='model.businessTeam'
				></h-select-company-input>
              </u-form-item> -->
				<u-form-item
					label="报名截止时间"
					prop="entriesEndDate"
					:borderBottom="false"
					required
				>
					<h-time-select
						v-model="model.entriesEndDate"
						placeholder="请选择报名截止时间"
						border="surround"
						suffixIcon="calendar-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"
						mode="datetime"
					></h-time-select>
				</u-form-item>
				<u-form-item
					label="投标截止时间"
					prop="tenderEndDate"
					:borderBottom="false"
					required
				>
					<h-time-select
						v-model="model.tenderEndDate"
						placeholder="请选择投标截止时间"
						border="surround"
						suffixIcon="calendar-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"
						mode="datetime"
					></h-time-select>
				</u-form-item>
				<u-form-item
					label="业主单位"
					prop="ownerUnit"
					:borderBottom="false"
					required
				>
					<h-select-customer-input
						style="width: 100%"
						v-model="model.ownerUnit"
						commercialType= "1"
						border="surround"
						placeholder="请选择业主单位"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
						objectField = 'model.ownerUnit'
						@input="onCustomerChange"
					></h-select-customer-input>
				</u-form-item>
				<u-form-item
					label="业主联系人"
					prop="ownerLinkman"
					:borderBottom="false"
					required
				>
					<h-dict-select
						style="width: 100%" 
						v-model="model.ownerLinkman" 
						placeholder="请选择业主联系人" 
						:dictName="cust_lxr"
						suffixIcon="arrow-down-fill" 
						:suffixIconStyle="{color: '#B2B2B2'}"
						@change="lxrChange"
					></h-dict-select>
				</u-form-item>
				<u-form-item
					label="业主联系方式"
					prop="ownerTel"
					:borderBottom="false"
					required
				>
					<u--input
						v-model="model.ownerTel"
						placeholder="请输入业主联系方式"
						border="surround"
					></u--input>
				</u-form-item>
				<u-form-item
					label="招标代理机构"
					prop="tenderAgent"
					:borderBottom="false"
					required
				>
					<u--input
						v-model="model.tenderAgent"
						placeholder="请输入招标代理机构"
						border="surround"
					></u--input>
				</u-form-item>
				<u-form-item
					label="招标代理联系人"
					prop="tenderAgentLinkman"
					:borderBottom="false"
					required
				>
					<u--input
						v-model="model.tenderAgentLinkman"
						placeholder="请输入招标代理联系人"
						border="surround"
					></u--input>
				</u-form-item>
				<u-form-item
					label="招标代理联系方式"
					prop="tenderAgentTel"
					:borderBottom="false"
					required
				>
					<u--input
						v-model="model.tenderAgentTel"
						placeholder="请输入招标代理联系方式"
						border="surround"
					></u--input>
				</u-form-item>
				
				<u-form-item
					label="招标方式"
					prop="biddingMethod"
					:borderBottom="false"
					ref="item1"
					required
				>
					<h-dict-select
						style="width: 100%" 
						v-model="model.biddingMethod" 
						placeholder="请选择招标方式" 
						dictName="bidding_method"
						suffixIcon="arrow-down-fill" 
						:suffixIconStyle="{color: '#B2B2B2'}"
					></h-dict-select>
				</u-form-item>
				<u-form-item
					label="招标控制价(元)"
					prop="controlPrice"
					:borderBottom="false"
					ref="item1"
					required
				>
					<h-money-input
						placeholder="请输入招标控制价"
						v-model="model.controlPrice"
					></h-money-input>
				</u-form-item>
				<u-form-item
					type="number"
					label="标书费(元)"
					prop="bidFee"
					:borderBottom="false"
					ref="item1"
					required
				>
					<h-money-input
						placeholder="请输入标书费"
						v-model="model.bidFee"
					></h-money-input>
				</u-form-item>
				<u-form-item
					label="投标保证金(元)"
					prop="tenderBond"
					:borderBottom="false"
					ref="item1"
					required
				>
					<h-money-input
						placeholder="请输入投标保证金"
						v-model="model.tenderBond"
					></h-money-input>
				</u-form-item>
				<u-form-item
					label="会员平台费(元)"
					prop="platformFee"
					:borderBottom="false"
					ref="item1"
					required
				>
					<h-money-input
						placeholder="请输入会员平台费"
						v-model="model.platformFee"
					></h-money-input>
				</u-form-item>
				
				<u-form-item
					label="项目公示信息"
					prop="projectPublicity"
					:borderBottom="false"
					ref="item1"
				>
					<u--textarea
						v-model="model.projectPublicity"
						:confirmType="null"
						count
						placeholder="请输入项目公示信息"
						:maxlength="500"
					></u--textarea>
				</u-form-item>
				<u-form-item
					label="投标内容概要"
					prop="tenderContent"
					:borderBottom="false"
					ref="item1"
				>
					<u--textarea
						v-model="model.tenderContent"
						:confirmType="null"
						count
						placeholder="请输入投标内容概要"
						:maxlength="500"
					></u--textarea>
				</u-form-item>
			</view>
		
			<!-- 附件 -->
			<view class="basic-style">
				<view class="basic-title-center">
					<u-line :length="120"></u-line>
					<view class="">招标文件</view>
					<u-line :length="120"></u-line>
				</view>
				<view class="warning">提示：请等待附件上传完成，再点击保存，否则附件无法保存成功！</view>
				<view class="" style="width: 100%;">
					<h-upload-file v-model="model.tenderFile" :isIcon="false" ></h-upload-file>
					<file-list v-if="model.tenderFile" v-model="model.tenderFile" :isDelete="true"></file-list>
				</view>
			</view>
			<view class="basic-style">
				<view class="basic-title-center">
					<u-line :length="105"></u-line>
					<view class="">投标任务信息</view>
					<u-line :length="105"></u-line>
				</view>
				<u-form-item
					label="投标单位"
					prop="tenderUnitId"
					:borderBottom="false"
					ref="item1"
					required
				>
					<h-select-company-input
					  style="width: 100%"
					  v-model="model.tenderUnitId"
					  border="surround"
					  placeholder="请选择投标单位"
					  suffixIcon="arrow-down-fill"
					  :suffixIconStyle="{ color: '#B2B2B2' }"
					  objectField="model.tenderUnitId"
						@input="onCompanyChange"
					></h-select-company-input>
				</u-form-item>
				<u-form-item
					label="投标部门"
					prop="tenderDept"
					:borderBottom="false"
					ref="item1"
				>
					<h-select-depart-input
						v-model="model.tenderDept"
						:departName="model.tenderDept_dictText"
						placeholder="请选择投标部门"
						border="surround"
						style="width: 100%;"
						suffixIcon="arrow-down-fill"
						multiple
						:suffixIconStyle="{color: '#B2B2B2'}"
						gradationSecondShow="gradationShow"
						@detail="ontenderDeptDetail1"
					></h-select-depart-input>
					
				</u-form-item>
			
				<ErpOmcTenderFileItemForm 
					@ok="onInforList" 
					ref="projectTaskFormConfig" 
					:assignedAmount="model.controlPrice" 
					:dataList="dataSource"
				></ErpOmcTenderFileItemForm>
				
				<u-form-item
					label="标书一审人"
					prop="bidReview1"
					:borderBottom="false"
					ref="item1"
					required
				>
					<h-select-person-input
						style="width: 100%"
						v-model="model.bidReview1"
						placeholder="请选择标书一审人"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
						objectField="model.bidReview1"
					></h-select-person-input>
					
				</u-form-item>
				<u-form-item
					label="标书二审人"
					prop="bidReview2"
					:borderBottom="false"
					ref="item1"
					required
				>
					<h-select-person-input
						style="width: 100%"
						v-model="model.bidReview2"
						placeholder="请选择标书二审人"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
						objectField="model.bidReview2"
					></h-select-person-input>
					
				</u-form-item>
				<u-form-item
					label="标书三审人"
					prop="thirdReviewer"
					:borderBottom="false"
					ref="item1"
				>
					<h-select-person-input
						style="width: 100%"
						v-model="model.thirdReviewer"
						placeholder="请选择标书三审人"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
						objectField="model.thirdReviewer"
					></h-select-person-input>
				</u-form-item>
				<view>
					<view class="basic-title-center">
						<u-line :length="120"></u-line>
						<view class="">商务附件</view>
						<u-line :length="120"></u-line>
					</view>
					<view class="warning">提示：请等待附件上传完成，再点击保存，否则附件无法保存成功！</view>
					<view class="" style="width: 100%;">
						<h-upload-file v-model="model.businessFile" :isIcon="false" ></h-upload-file>
						<file-list v-if="model.businessFile" v-model="model.businessFile" :isDelete="true"></file-list>
					</view>
				</view>
				
				<u-form-item
					label="开标方式"
					prop="bidMethod"
					:borderBottom="false"
					ref="item1"
					required
				>
					<h-dict-select
						style="width: 100%" 
						v-model="model.bidMethod" 
						placeholder="请选择开标方式" 
						dictName="tender_bid_method" 
						suffixIcon="arrow-down-fill" 
						:suffixIconStyle="{color: '#B2B2B2'}"
					></h-dict-select>
				</u-form-item>
				<u-form-item
					label="文件类型"
					prop="fileType"
					:borderBottom="false"
					ref="item1"
				>
					<h-dict-multi-select
						v-model="model.fileType"
						style="width: 100%" 
						placeholder="请选择文件类型"
						dictName="tender_file_type"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></h-dict-multi-select>
				</u-form-item>
				<u-form-item
					label="备注"
					prop="comments"
					:borderBottom="false"
					ref="item1"
				>
					<u--textarea
						v-model="model.comments"
						:confirmType="null"
						count
						placeholder="请输入备注"
						:maxlength="500"
					></u--textarea>
				</u-form-item>
			</view>
			
			<view class="basic-style">
				<view class="basic-title-center">
					<u-line :length="120"></u-line>
					<view class="">用印信息</view>
					<u-line :length="120"></u-line>
				</view>
				<u-form-item
					label="报价文件用印"
					prop="isSeal"
					:borderBottom="false"
					required>
					<h-dict-radio v-model="model.isSeal" dictName="yn" @input="handleChangeSeal"></h-dict-radio>
				</u-form-item>
				<view v-if="model.isSeal === '1'">
					<u-form-item label="用印类型" prop="signSealWay" required>
					  <h-select-input-tag
					    class="w-100"
					    v-model="model.signSealWay"
					    objectField="model.signSealWay"
					    placeholder="请选择用印类型"
							suffixIcon="arrow-down-fill"
							:suffixIconStyle="{ color: '#B2B2B2' }"
					    border="surround"
					    dictName="seal_way"
					  ></h-select-input-tag>
					</u-form-item>
					<u-form-item
						label="是否借出"
						prop="lendYn"
						:borderBottom="false"
						required>
						<h-dict-radio v-model="model.lendYn" dictName="yes_no"></h-dict-radio>
					</u-form-item>
				  <u-form-item label="文件份数" prop="quantity" required>
						<h-number-input placeholder="请输入文件份数" v-model="model.quantity" :digit="0" :min="0" :max="99999999"></h-number-input>
				  </u-form-item>
					<u-form-item
						required
						label="用印说明"
						prop="userExplain"
						:borderBottom="false"
						ref="item1">
						<!-- #ifdef H5 -->
						<u--textarea
							v-model="model.userExplain"
							placeholder="请输入用印说明"
							confirm-type="done"
							:maxlength="500"
						></u--textarea>
						<!-- #endif -->
						<!-- #ifndef H5 -->
						<u--textarea
							v-model="model.userExplain"
							:confirmType="null"
							count
							placeholder="请输入用印说明"
							:maxlength="500"
						></u--textarea>
						<!-- #endif -->
					</u-form-item>
					<u-form-item label="选择印章" prop="sealIds" :borderBottom="false" required>
						<h-select-seal-input style="width: 100%;" v-model="model.sealIds" objectField="model.sealIds"
							placeholder="请选择印章" border="surround" suffixIcon="arrow-down-fill"
							:suffixIconStyle="{color: '#B2B2B2'}" :sealCompany="model.tenderUnitId">
						</h-select-seal-input>
					</u-form-item>
					<template>
						<SealFormInfo
							v-for="(item, index) in formData"
							:key="index"
						  :item="item"
						  :index="index"
						/>
					</template>
				</view>
			</view>
			<view class="basic-style" v-if="model.isSeal === '1'">
			  <view class="basic-title basic-border">用印文件<span style="color: #faad14;font-weight: 600">（请上传只需盖章的用印文件！）</span></view>
			  <u-form-item label="用印文件" prop="signFile" required>
					<view class="py-1 space-y-1" style="width: 100%">
						<view style="color: red">提示：请等待附件上传完成，再点击保存，否则附件无法保存成功！</view>
						<h-upload-file v-model="model.signFile" :fillSize="50" :isIcon="false" :isSingle="true" fileType=".pdf, .PDF, .doc, .docx" fileTypeText="请上传word与pdf格式的文件！"></h-upload-file>
						<file-list v-if="model.signFile" v-model="model.signFile" :isDelete="true"></file-list>
					</view>
				</u-form-item>
			</view>
			
			<view class="space-x-1 px-1 btn_position">
				<u-button :disabled="isSubmit" type="primary" :plain="true" text="保存" @click="onDrafts"></u-button>
				<u-button :disabled="isSubmit"  type="primary"  text="保存并提交" @click="onSubmit"></u-button>
			</view>
			<view style="height: 100rpx;"></view>
		</u--form>
		<u-toast ref="uToast"></u-toast>
		<ProcessNodeConfiguration ref="processConfig" @ok="onOk"></ProcessNodeConfiguration>
	</view>
</template>
<script>
import fileList from '@/pages/synergy/components/fileList.vue'
import ErpOmcTenderFileItemForm from './components/ErpOmcTenderFileItemForm.vue' // 业务分类组件
import ProcessNodeConfiguration from '@/components/ProcessNodeConfiguration/ProcessNodeConfiguration.vue' // 流程节点配置人员选择弹窗
import {
	generatedFormNumber, // 获取单据编号
	erpOmcCustomerManagerContactId, // 获取联系方式
	erpOmcTenderFileAdd, // 添加
	erpOmcTenderFileEdit, // 编辑
	erpOmcTenderFileQueryById, // 详情
	queryByIdTenderPersonFile, // 获取子表
	queryTenderListByTenderId, // 文件審核子表
	queryByIdQualificationChild, // 印章列表
} from '@/api/index.js'
import moment from 'moment'
import http from '@/utils/request/index.js' // 请求方式
import SealFormInfo from '@/pages/seal/components/SealFormInfo.vue'
import {
	BASE_URL
} from '@/utils/baseUrl.js'
import { convertCurrency } from '@/utils/MoneyConvert' // 金额大写转换
var projectId = ''
export default {
	components: {
		fileList,
		ErpOmcTenderFileItemForm,
		ProcessNodeConfiguration,
		SealFormInfo
	},
	data() {
		return {
			isSubmit: false,
			formData: [], // 印章列表
			model: {
				bidNo: '', //单据编号
				businessCompanyId: '', // 经营公司
				createTime: '', // 申请时间
				proposer: '', // 申请人
				proposerDeptId: '', // 申请部门
				tenderId: '', // 投标档案
				projectName: '', // 项目名称
				undertaker: '', // 项目承接人
				year: '', // 业绩发归属年度
				projectAddress: '', // 项目所在地址
				detailedAddress: '', // 项目详细地址
				businessTeam: '', // 经营团队
				entriesEndDate: '', // 报名截止时间
				tenderEndDate: '', // 投标截止时间
				ownerUnit: '', // 业主单位
				ownerLinkman: '', // 业主联系人
				ownerTel: '', // 业主联系方式
				tenderAgent: '', // 招标代理机构
				tenderAgentLinkman: '', //招标代理联系人
				tenderAgentTel: '', // 招标代理联系方式
				biddingMethod: '', // 招标方式
				controlPrice: '', // 招标控制价
				bidFee: '', // 标书费
				tenderBond: '', // 投标保证金
				platformFee: '', // 会员平台费
				projectPublicity: '', // 项目公式信息
				tenderContent: '', // 投标内容概要
				tenderFile: '', // 招标文件
				tenderUnitId: '', // 投标单位
				bidReview1: '', // 标书一审
				bidReview2: '', // 标书二审
				thirdReviewer: '', // 标书三审
				isSeal: '0', // 报价文件用印
				signSealWay: '', // 用印类型
				lendYn: '', // 是否借出
				quantity: '', // 文件份数
				userExplain: '', // 用印说明
				sealIds: '', // 选择印章
				signFile: '', // 用印文件
			},
			cust_lxr: 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=0',
			id: '', // 详情id值
			dataSource: [], // 业务分类信息列表
			rules: {
				bidNo: [{ required: true, message: '请输入单据编号!', trigger: ['blur', 'change'] }],
				proposerDeptId: [{ required: true, message: '请选择申请部门!', trigger: ['blur', 'change'] }],
				proposer: [{ required: true, message: '请选择申请人!', trigger: ['blur', 'change'] }],
				createTime: [{ required: true, message: '请选择申请时间!', trigger: ['blur', 'change'] }],
				
				tenderUnit: [
					{ required: true, message: '请选择投标单位!', trigger: ['change','blur'], },
				],
				tenderId: [
				   { required: true, message: '请选择关联投标档案编号!', trigger: ['change','blur'] },
				],
				projectName: [
					{ required: true, message: '请选择项目名称!', trigger: ['change','blur'], },
					{
						asyncValidator: (rule, value, callback) => {
							let params = {
								projectName: value,
								projectId: projectId,
								type: 'tenderFile' // 立项：project  预立项：prepare 投标文件审核：tenderFile  投标结果申请：tenderResult
							}
							http.get('/api/erp/omc/project/erpOmcProject/checkProjectDuplicate', params).then(res => {
								// 如果验证不通过，需要在callback()抛出new Error('错误提示信息')
								if (res.success) {
									callback();
								} else {
									callback(new Error(res.message));
								}
							}).catch(err => {
								callback(new Error(err.message));
							})
						},
						trigger: ['blur']
					},
				],
				undertaker: [
					{ required: true, message: '请选择承接人!', trigger: ['change','blur'], },
				],
				year: [
					{ required: true, type: 'number',  message: '请选择业绩归属年度!', trigger: ['change','blur'], },
				],
				projectAddress: [
				  { required: true, message: '请选择项目地址!', trigger: ['change','blur'], },
				],
				detailedAddress: [
				  { required: true, message: '请输入项目详细地址!', trigger: ['change','blur'], },
				],
				businessTeam: [
				  { required: true, message: '请选择经营团队!', trigger: ['change','blur'], },
				],
				entriesEndDate: [
					{ required: true, message: '请选择报名截止日期!', trigger: ['change','blur'], }
				],
				tenderEndDate: [
					{ required: true, message: '请选择投标截止日期!', trigger: ['change','blur'], }
				],
				ownerUnit: [
				  { required: true, message: '请选择业主单位!', trigger: ['change','blur'], },
				],
				ownerLinkman: [
				  { required: true, message: '请选择业主联系人!', trigger: ['change','blur'], },
				],
				ownerTel: [
					{ required: true, message: '请输入业主联系方式！', trigger: ['change', 'blur'], },
					{ required: true, pattern: /(^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$)|(^\/$)/, message: '请输入正确的联系方式!', trigger: ['change', 'blur'] }
				],
				tenderAgent: [
					{ required: true, message: '请输入招标代理机构', trigger: ['change','blur'] }
				],
				tenderAgentLinkman: [
					{ required: true, message: '请选择招标代理联系人!', trigger: ['change','blur'] }
				],
				tenderAgentTel: [
					{ required: true, message: '请输入招标代理联系方式！', trigger: ['change', 'blur'], },
					{
						// 自定义验证函数，见上说明
						validator: (rule, value, callback) => {
							// 返回true表示校验通过，返回false表示不通过
							var reg = /(^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$)|(^\/$)/
							if (reg.test(value)) {
								return true
							} else {
								return false
							}
							// return uni.$u.test.mobile(value);
						},
						message: '请输入正确的联系方式!',
						// 触发器可以同时用blur和change
						trigger: ['change','blur']
					}
				],
				
				biddingMethod: [
					{ required: true, message: '请选择招标方式!', trigger: ['change', 'blur'] }
				],
				controlPrice: [
					{
						type: 'number',
						required: true, message: '请输入招标控制价!',
						// pattern: '/(^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$)|(^\/$)/',
						trigger: ['change','blur']
					},
					{
						validator: (rule, value, callback) => {
							// 上面有说，返回true表示校验通过，返回false表示不通过
							// uni.$u.test.mobile()就是返回true或者false的
							return uni.$u.test.amount(value);
						},
						message: '请输入正确的金额!',
						// 触发器可以同时用blur和change
						trigger: ['blur']
					}
				],
				bidFee: [
					{
						type: 'number',
						required: true, message: '请输入标书费!',
						trigger: ['blur']
					},
					{
						validator: (rule, value, callback) => {
							// 上面有说，返回true表示校验通过，返回false表示不通过
							// uni.$u.test.mobile()就是返回true或者false的
							return uni.$u.test.amount(value);
						},
						message: '请输入正确的金额!',
						// 触发器可以同时用blur和change
						trigger: ['blur']
					}
				],
				tenderBond: [
					{
						type: 'number',
						required: true, message: '请输入投标保证金!',
						trigger: ['blur']
					},
					{
						validator: (rule, value, callback) => {
							// 上面有说，返回true表示校验通过，返回false表示不通过
							// uni.$u.test.mobile()就是返回true或者false的
							return uni.$u.test.amount(value);
						},
						message: '请输入正确的金额!',
						// 触发器可以同时用blur和change
						trigger: ['blur']
					}
				],
				platformFee: [
					{
						type: 'number',
						required: true, message: '请输入会员平台费!',
						trigger: ['change','blur']
					},
					{
						validator: (rule, value, callback) => {
							// 上面有说，返回true表示校验通过，返回false表示不通过
							// uni.$u.test.mobile()就是返回true或者false的
							return uni.$u.test.amount(value);
						},
						message: '请输入正确的金额!',
						// 触发器可以同时用blur和change
						trigger: ['blur']
					}
				],
				bidMethod: [
				  { required: true, message: '请选择开标方式!', trigger: ['change','blur'] },
				],
				bidReview1: [
				  { required: true, message: '请选择标书一审人!', trigger: ['change','blur'] },
				],
				bidReview2: [
				  { required: true, message: '请选择标书二审人!', trigger: ['change','blur'] },
				],
				tenderUnitId: [
				  { required: true, message: '请选择投标单位!', trigger: ['change','blur'] },
				],
				
				isSeal: [
					{ required: true, message: '请选择报价文件用印!', trigger: ['change','blur'] },
				],
				signSealWay: [
					{ required: true, message: '请选择用印类型!', trigger: ['change','blur'] },
				],
				lendYn: [
					{ required: true, message: '请选择是否借出!', trigger: ['change'] },
				],
				quantity: [
					{ required: true, message: '请输入文件份数!', trigger: ['change','blur'] },
				],
				userExplain: [
					{ required: true, message: '请输入用印说明!', trigger: ['change','blur'] },
				],
				sealIds: [
					{ required: true, message: '请选择印章!', trigger: ['change','blur'] },
				],
				signFile: [
					{ required: true, message: '请选择用印文件!', trigger: ['change','blur'] },
				],
			},
			
			
			//代码生成后需手动设置流程编码
			flowCode: 'onl_erp_omc_tender_file',
			processId: '1557902925824761858',
			formUrl: 'erp/omc/tenderfile/modules/ErpOmcTenderFileForm',
			beanName: 'erpOmcTenderFileServiceImpl',
			formUrlMobile: '/pages/synergy/erpOmcTenderFileList',
		};
	},
	
	computed: {
	    // 投标审核需要动态禁用的状态字段
	    editFildDisabled() {
	      // 新增和变更的时候只能看不能填
	      return true
	    },
	  },
	onLoad(options) {
		if (options.id) {
			// 编辑
			this.edit(options.id)
		} else {
			// 添加
			this.add()
		}
		
	},
	watch: {
		'model.sealIds': {
			handler (val) {
				this.getChildData(val)
			},
			immediate: true
		}
	},
	methods: {
     
		changeBusinessCompany(val){
      this.model.businessCompanyId = val.belongCompanyId
                        
      },
		// 获取印章列表
		getChildData(ids){
			if (!ids){
				this.formData = []
				return false
			}
			queryByIdQualificationChild({ ids}).then(res => {
				if(res.success){
					this.formData = res.result || []
					if (res.result && res.result.length) {
						var sealIds_dictText = ''
						res.result.map(value => {
							sealIds_dictText = sealIds_dictText  + ',' + value.sealType_dictText?value.sealType_dictText:value.sealType
						})
						sealIds_dictText = sealIds_dictText.slice(1) 
						this.formData.sealIds_dictText = sealIds_dictText
					}
					
				}
			})
		},
		// 选择保价文件用印
		handleChangeSeal(val) {
			if (val == '1') {
				this.$refs.ErpOmcProjectApplyForm.clearValidate(['signSealWay', 'lendYn', 'quantity', 'userExplain', 'sealIds', 'signFile']);
			}
			this.$set(this.model, 'signSealWay', '')
			this.$set(this.model, 'lendYn', '')
			this.$set(this.model, 'quantity', '')
			this.$set(this.model, 'userExplain', '')
			this.$set(this.model, 'sealIds', '')
			this.$set(this.model, 'signFile', '')
		},
		// 印章资质所属公司
		onCompanyChange (item) {
			this.$set(this.model, 'sealIds', '')
		},
		// 编辑
		async edit(id) {
			// 获取详情
			this.getDetail(id)
			this.getErpOmcProjectTaskList(id)
		},
		// 获取详请
		async getDetail (id) {
			erpOmcTenderFileQueryById({ id }).then(async res => {
				if (res.success) {
					this.cust_lxr = await 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + res.result.ownerUnit + '\'';
					this.model = await {...res.result};
					if (this.model.tenderId) {
						http.get('/api/erp/omc/tender/erpOmcTenderFinal/queryById', { id: this.model.tenderId }).then(async(res) => {
							if (res.success) {
								projectId = res.result.prepareProjectId
							}
						})
					}
					this.model.year = this.model.year + ''
					if (this.model.lendYn !== null || this.model.lendYn !== ''){
						this.model.lendYn = this.model.lendYn + ''
					}
					this.$nextTick(() => {
						this.model.ownerLinkman = res.result.ownerLinkman
						this.model.ownerTel = res.result.ownerTel
					})
				}
			})
		},
		
		// 获取流程列表
		getProcessList (id) {
			if (this.isSubmit) {
				http.get('/api/erp/omc/contractmanager/erpOmcContractManagerFinal/totalCount', { tenderFinalCode: this.model.tenderFinalCode }).then(res => 				{
					if (res.success) {
						if (res.result <= 0){
							//校验通过
							this.$refs.processConfig.showPopup = true
							this.$refs.processConfig.formUrl = this.formUrl
							this.$refs.processConfig.formUrlMobile = this.formUrlMobile
							this.$refs.processConfig.flowCode = this.flowCode
							this.$refs.processConfig.edit(id, this.processId, this.beanName)
						}else{
							//校验不通过
							this.$refs.uToast.show({
								message: '该项目已签收款合同，无法进行投标!',
								complete () {
									if (getCurrentPages().length > 1) {
										uni.navigateBack()
									} else {
										uni.reLaunch({
											url: '/pages/home/home'
										})
									}
									
								}
							})
						}
					} else {
						this.$refs.uToast.show({
							message: res.message,
							complete () {
								if (getCurrentPages().length > 1) {
									uni.navigateBack()
								} else {
									uni.reLaunch({
										url: '/pages/home/home'
									})
								}
								
							}
						})
					}
				})
			}
		},
		
		// 获取分类信息列表
		getErpOmcProjectTaskList (id) {
			queryByIdTenderPersonFile({ id: id }).then(res => {
				if (res.success) {
					this.dataSource = res.result.records || res.result
				}
			})
		},
		
		// 投标部门详情
		ontenderDeptDetail(item) {
		  var title = ''
		  if (item && item.length) {
		    item.map((value, index) => {
		      title = value.departName + ',' + title
		    })
		    title = title.substring(0, title.lastIndexOf(','))
		  }
		  this.model.proposerDeptText = title
		  
		},
		ontenderDeptDetail1 (item) {
			var title = ''
			if (item && item.length) {
				item.map((value, index) => {
					title = value.name + ',' + title
					
				})
				title = title.substring(0, title.lastIndexOf(','))
			}
			this.model.tenderDept_dictText = title
		},
		
		
		// 投标档案选择
		tenderFinalChange(tenderFinal) {
			this.cust_lxr = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + tenderFinal.ownerUnit + '\'';
			projectId = tenderFinal.prepareProjectId
			this.tenderEndDate = tenderFinal.tenderEndDate //投标结束日期
			this.entriesEndDate = tenderFinal.entriesEndDate //报名截止时间
			this.$set(this.model,'tenderEndDate',tenderFinal.tenderEndDate) //投标结束日期
			this.$set(this.model,'entriesEndDate',tenderFinal.entriesEndDate) //报名截止时间
			this.$set(this.model,'bidFee',tenderFinal.entryFee) //标书费（元）
			this.$set(this.model,'tenderBond',tenderFinal.tenderBond) //投标保证金（元）
			this.$set(this.model,'undertaker',tenderFinal.undertaker)
			this.$set(this.model,'year',tenderFinal.year + '')
			this.$set(this.model,'tenderFinalCode',tenderFinal.finalNo)
			this.$set(this.model, 'projectName', tenderFinal.projectName)
			this.$set(this.model, 'projectType', tenderFinal.projectType)
			this.$set(this.model,'projectAddress',tenderFinal.projectAddress)
			this.$set(this.model,'detailedAddress',tenderFinal.detailedAddress)
			this.$set(this.model,'ownerUnit',tenderFinal.ownerUnit)
			this.$set(this.model,'ownerLinkman',tenderFinal.ownerLinkman)
			this.$set(this.model,'businessTeam',tenderFinal.businessTeam)
			this.$set(this.model,'businessCompanyId',tenderFinal.businessCompanyId)
			this.$set(this.model,'ownerTel',tenderFinal.ownerTel)
			this.$set(this.model,'biddingMethod',tenderFinal.biddingMethod)
			this.$set(this.model,'tenderContent',tenderFinal.tenderContent)
			this.$set(this.model,'tenderFile',tenderFinal.tenderFile)
			this.$set(this.model,'controlPrice',tenderFinal.controlPrice)
			// BUG#3276
			this.$set(this.model,'projectPublicity',tenderFinal.projectPublicity)

			//todo 迭代11 根据投标档案带出数据
			this.$set(this.model,'tenderUnit',tenderFinal.tenderUnit)

			// 查询投标单位
			queryTenderListByTenderId({ id: tenderFinal.id }).then((res) => {
				if (res.success) {
				  this.dataSource = res.result || []
				}
			})
			this.$refs.ErpOmcProjectApplyForm.clearValidate() // 清空校验结果
		},
		
		// 添加
		add() {
			this.getGeneratedFormNumber()
			this.model.createTime = moment().format('YYYY-MM-DD HH:mm:ss'); // 申请时间
			this.model.proposer = uni.getStorageSync('userInfo').empId; //申请人
			this.model.proposerDeptId = uni.getStorageSync('userInfo').deptId; //申请部门
			projectId = ''
		},
		// 获取单据编号
		getGeneratedFormNumber() {
			generatedFormNumber({ prefix: 'TBWJ', subSystemCode: '05' }).then(res => {
				if (res.success) {
					this.$set(this.model, 'bidNo', res.result)
				}
			})
		},
		
		
		// 监听修改本次合同额数据
		convertMoneyBlur2 (item) {
			let money = Number(this.model.controlPrice)
			if (this.model.controlPrice) {
				this.$set(this.model, 'controlPrice', money.toFixed(2))
			}
		},
		
		// 选择业主单位
		onCustomerChange () {
			this.cust_lxr = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + this.model.ownerUnit + '\'';
			this.$set(this.model, 'ownerLinkman', '')
			this.$set(this.model, 'ownerTel', '')
		},
		// 选择联系人
		lxrChange (val) {
			var params = {id: val}
			this.$set(this.model, 'ownerLinkman', val)
			erpOmcCustomerManagerContactId(params).then(res => {
				if (res.success) {
					let data = res.result.records || res.result
					this.$set(this.model, 'ownerTel', data.lxfs)
				} else {
					this.$refs.uToast.show({
						message: res.message,
						type: 'error'
					})
				}
			})
		},
		
		onInforList (item) {
			this.dataSource = item
		},
		
		validateForm() {
			return this.$refs.ErpOmcProjectApplyForm.validate().then(async () => {
				var that = this
				let params = {
					projectName: that.model.projectName,
					projectId: projectId,
					type: 'tenderFile' // 立项：project  预立项：prepare 投标文件审核：tenderFile  投标结果申请：tenderResult
				}
				return http.get('/api/erp/omc/project/erpOmcProject/checkProjectDuplicate', params).then(async res => {
					// 如果验证不通过，需要在callback()抛出new Error('错误提示信息')
					if (!res.success) {
						return Promise.reject(res.message)
					}
				}).catch(async err => {
					return Promise.reject(err.message)
				})
			})
		},
		// 点击提交
		async onSubmit () {
			var that = this
			await this.validateForm()
			this.model.personList = this.dataSource;
			let httpurl = '';
			if (!this.model.id) {
				httpurl = erpOmcTenderFileAdd;
			} else {
				httpurl = erpOmcTenderFileEdit;
			}
			httpurl(this.model).then(res => {
				if (res.success) {
					var that = this
					this.isSubmit = true
					// 获取流程列表
					if (this.model.id) {
						this.getProcessList(this.model.id)
					} else {
						// 判断添加的时候是否有返回id值
						if (res.result) {
							this.getProcessList(res.result)
						}
						
					}
					this.$refs.uToast.show({
						message: res.message,
						type: 'default',
						complete () {
							that.isSubmit = false
						}
					})
					
					
				} else {
					this.$refs.uToast.show({
						message: res.message,
						type: 'error'
					})
				}
			})
		},
		
		onDrafts() {
			var that = this
			this.model.personList = this.dataSource || [];
			let httpurl = '';
			if (!this.model.id) {
				httpurl = erpOmcTenderFileAdd;
			} else {
				httpurl = erpOmcTenderFileEdit;
			}
			httpurl(this.model).then(res => {
				if (res.success) {
					var that = this
					this.isSubmit = true
					this.$refs.uToast.show({
						message: res.message,
						type: 'default',
						complete () {
							that.isSubmit = false
							// uni.navigateBack()
							if (getCurrentPages().length > 1) {
								uni.navigateBack()
							} else {
								uni.reLaunch({
									url: '/pages/home/home'
								})
							}
							
						}
					})
					
					
				} else {
					this.$refs.uToast.show({
						message: res.message,
						type: 'error'
					})
				}
			})
		},
		
		// 提交流程成功
		onOk () {
			this.$refs.uToast.show({
				message: '提交成功',
				type: 'success',
				complete () {
					if (getCurrentPages().length > 1) {
						uni.navigateBack()
					} else {
						uni.reLaunch({
							url: '/pages/home/home'
						})
					}
					
				}
			})
		}
	}
};
</script>

<style lang="scss" scoped>
@import url("@/assets/inputStyle.scss");
</style>